package com.zw.es;
import com.google.gson.GsonBuilder;

import io.searchbox.client.JestClient;
import io.searchbox.client.JestClientFactory;
import io.searchbox.client.config.HttpClientConfig;
import io.searchbox.client.http.JestHttpClient;
import org.springframework.stereotype.Component;

/**
 * Created by Zw on 2018/3/9.
 */
@Component
public class InitElasticSearchConfig {
    public static final String esUrl = "http://127.0.0.1:9200/";

    private JestClient client;

    public InitElasticSearchConfig(){
        JestClientFactory factory = new JestClientFactory();
        factory.setHttpClientConfig(new HttpClientConfig
                .Builder(esUrl)
                .gson(new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create())
                .multiThreaded(true)
                .readTimeout(10000)
                .build());
         client = factory.getObject();
    }

    public JestClient getClient() {
        return client;
    }


}
